import { defineStore } from "pinia";

interface IMSocket {
    isPhone: boolean;
    socketId: string;
    state: string;
    userName: string;
    userId: string;
    roomName: string;
    roomId: string;
    roomMaster: string;
    members: string[];
    peerConn: RTCPeerConnection | null;
    peerConns: RTCPeerConnection[];
    stream: MediaStream | null;
    localOffer: any;
    remoteOffer: any;
}
export const useSocketStore = defineStore({
    id: "imsocket",
    state: (): IMSocket => {
        return {
            isPhone: false,
            socketId: "",
            state: "初始化",
            userName: "小明",
            userId: "",
            roomName: "",
            roomId: "",
            roomMaster: "",
            members: [],
            peerConn: null,
            peerConns: [],
            stream: null,
            localOffer: null,
            remoteOffer: null
        };
    },
    getters: {},
    actions: {
        setUser(user: string, id: string) {
            this.userName = user;
            this.userId = id;
        },
        clearUser() {
            this.userName = "";
            this.userId = "";
        },
        clearRoom() {
            this.roomId = "";
            this.roomMaster = "";
            this.roomName = "";
        }
    }
});
